import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:ichinesereader/controller/evaluation.dart';
import 'package:ichinesereader/models/report/evaluationLevelChartData.dart';
import 'package:ichinesereader/utils/log.dart';
import 'package:ichinesereader/widgets/charts/evaluationLevelAverageSeries.dart';

class EvaluationReportsACTFL extends GetView<EvaluationController> {
  @override
  Widget build(BuildContext context) {
    Log.debug('build teacher evaluation actfl reports');

    return Scaffold(
      body: SingleChildScrollView(
        primary: false,
        scrollDirection: Axis.vertical,
        padding: const EdgeInsets.all(8.0),
        child: Padding(
          padding: const EdgeInsets.all(8.0),
          child: Center(
            child: Column(
              children: [
                Container(
                  decoration: BoxDecoration(
                    border: Border.all(
                      color: const Color(0xff7c94b6),
                      width: 0.5,
                    ),
                    borderRadius: BorderRadius.circular(12),
                  ),
                  height: 450,
                  width: context.width - 20,
                  child: controller.obx(
                    (data) {
                      List<EvaluationLevelChart> chartData = [];
                      if (controller.evaluationOverviewData.value.actflLevel !=
                          null) {
                        controller.evaluationOverviewData.value.actflLevel
                            ?.forEach((item) {
                          EvaluationLevelChart chart = EvaluationLevelChart(
                              item.level.toString(),
                              item.listeningAccuracy! / 10,
                              item.speakingScore?.toDouble(),
                              item.speakingAiScore! / 10,
                              item.readingAccuracy! / 10,
                              item.writingScore?.toDouble(),
                              0);
                          chartData.add(chart);
                        });
                      }
                      return EvaluationLevelMultipleSeries(
                        levelChartData: chartData,
                        chartTitle: 'Class Average'.tr,
                        xLabel: 'Score'.tr,
                        yLabel: '',
                      );
                    },
                    onEmpty: Text('Data not available ...'.tr),
                    onLoading: Center(
                        child: CircularProgressIndicator(
                      backgroundColor: Get.theme.primaryColorDark,
                      strokeWidth: 9.0,
                    )),
                  ),
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }
}
